11. Quiz: Color Threshold

Create a color mask

In this example, it will be up to you to create a color threshold of your own and use it to mask the red portion of a stop sign! See how your code performs by clicking the Test Run button on this quiz and try to get your output to look like the masked image pictured below.

(Left) Original stop sign, (Right) Masked stop sign

(Left) Original stop sign, (Right) Masked stop sign

Note on Code Quizzes

  1. Some code will have been implemented for you, typically at the top of a quiz and again at the bottom for display. The code you need to implement will be marked as TODO tasks.

  2. To see the image or text output of a quiz, click Test Run. In fact, it's always a good idea to test your code before you submit it!

  3. Finally, to see if your answer was correct, click Submit Answer. You can submit multiple times.

  4. You can restart this quiz and set it back it's original state at any time by pressing the Reset Quiz button.

Start Quiz:

import matplotlib.pyplot as plt
import numpy as np
import cv2

# Read in the image
image = cv2.imread('stop_sign.jpg')
# Convert to RGB
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# ---------------------------------------------------------- #


## TODO: Define the color selection criteria
lower_red = np.array([0,0,0]) 
upper_red = np.array([0,0,0])

# Mask the image 
masked_image = np.copy(image)
mask = cv2.inRange(masked_image, lower_red, upper_red)

## TODO: Apply the mask to masked_image
## by setting the pixels in the red range to black
## Click `Test Run` to display the output before submitting



# ---------------------------------------------------------- #
# Display it
plt.imshow(masked_image)